<template>
<el-card class="box-card login">
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="pass">
            <el-input type="text" v-model="ruleForm.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="checkPass">
            <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
            <el-button @click="$router.push({path: '/reg'})">注册</el-button>
        </el-form-item>
    </el-form>
</el-card>

</template>

<script>
import {login} from '../service/userManage/user'
export default {
    data() {
      
      return {
        ruleForm: {
          pass: '',
          checkPass: '',
         
        },
        rules: {
          pass: [
              {required:true ,message:'登录名不能为空'},
          ],
          checkPass: [
              {required:true ,message:'密码不能为空'},  
          ],
          
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate(async (valid) => {
          if (valid) {
            let r = await login(this.ruleForm.pass, this.ruleForm.checkPass);
            console.log(r);
            if(r.data == true){
                this.$router.push({path: '/sss'}); 
            }

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style>
.login{
    width: 480px;
    margin:  200px auto;
}
</style>